﻿using System.Collections.Generic;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using TSharp.Core.Aop.Handler;

namespace TSharp.Core.Aop.Attributes
{
	/// <summary>
	///  验证方法中参数不为null的定制特性
	/// </summary>
	public class NotNullAttribute : HandlerAttribute
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="NotNullAttribute"/> class.
		/// </summary>
		/// <param name="parameterName">Name of the parameter.</param>
		public NotNullAttribute(params string[] parameterName)
		{
			ParameterName = new List<string>();
			foreach (string name in parameterName)
			{
				ParameterName.Add(name);
			}
		}

		/// <summary>
		/// 不为空的参数名
		/// </summary>
		public IList<string> ParameterName { get; set; }

		/// <summary>
		/// Derived classes implement this method. When called, it
		/// creates a new call handler as specified in the attribute
		/// configuration.
		/// </summary>
		/// <param name="container">The <see cref="T:Microsoft.Practices.Unity.IUnityContainer"/> to use when creating handlers,
		/// if necessary.</param>
		/// <returns>A new call handler object.</returns>
		public override ICallHandler CreateHandler(IUnityContainer container)
		{
			return new NotNullHandler(ParameterName, Order);
		}
	}
}